<template>
  <view class="goods-item" @click="goToDetail(goods.goods_id)">
    <view class="goods-item-left">
      <slot name="radio" />
      <image
        class="goods-pic"
        :src="goods.goods_small_logo || defaultImg"
        mode="scaleToFill"
      />
    </view>
    <view class="goods-item-right">
      <text class="goods-name">{{ goods.goods_name }}</text>
      <view class="price-number">
        <text class="goods-price">￥{{ goods.goods_price | tofixed }}</text>
        <slot name="num" />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      defaultImg: '../../static/logo.png'
      // 加载出来是一个base64图片格式
      // defaultImg: require('../../static/logo.png')
    }
  },
  filters: {
    tofixed (val) {
      return val.toFixed(2)
    }
  },
  props: {
    goods: {
      type: Object,
      default: () => {}
    }
  },
  methods: {
    goToDetail (goods_id) {
      uni.navigateTo({
        url: `../../subpkg/goods-detail/index?goods_id=${goods_id}`
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    margin-right: 5px;
    display: flex;
    align-items: center;
    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .goods-name {
      font-size: 13px;
    }
    .price-number {
      display: flex;
      // align-items: center;
      justify-content: space-around;
      .goods-price {
        font-size: 16px;
        color: #c00000;
      }
    }
  }
}
</style>
